<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>icf</title>

	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="/public/layui/admin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="/public/layui/admin/style/admin.css" media="all">
</head>


<body>

<script type="text/html" id="app_item_edit_pop">

		<div class="layui-card-header">AppSuitItem</div>

		<div class="layui-card-body" style="padding: 15px;">
			<!--<form class="layui-form" action="" lay-filter="component-form-group">-->

				<input name="id" type="hidden" value="{{ data.detail.Id }}"/>


				<!-- todo #FormFieldsHtml# -->

				<!--
<div class="layui-form-item">
	<label class="layui-form-label">id</label>
	<div class="layui-input-block">
		<input type="text"
			   id="id"
			   name="id"
			   value="{{ data.detail.Id }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->
				<!--
<div class="layui-form-item">
	<label class="layui-form-label">deleted</label>
	<div class="layui-input-block">
		<input type="text"
			   id="if_del"
			   name="if_del"
			   value="{{ data.detail.IfDel }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->
				<!--
<div class="layui-form-item">
	<label class="layui-form-label">create</label>
	<div class="layui-input-block">
		<input type="text"
			   id="cdate"
			   name="cdate"
			   value="{{ data.detail.Cdate }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->
				<!--
<div class="layui-form-item">
	<label class="layui-form-label">update</label>
	<div class="layui-input-block">
		<input type="text"
			   id="udate"
			   name="udate"
			   value="{{ data.detail.Udate }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->


				<div class="layui-form-item">
					<label class="layui-form-label">APP套餐ID</label>
					<div class="layui-input-block">
						<input type="text"
							   id="app_suit_id"
							   name="app_suit_id"
							   value="<%= app_suit_id %>"
							   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
					</div>
				</div>



				<div class="layui-form-item">
					<label class="layui-form-label">APP套餐码</label>
					<div class="layui-input-block">
						<input type="text"
							   id="suit_code"
							   name="suit_code"
							   value="<%= suit_code %>"
							   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
					</div>
				</div>

			<div class="layui-form-item">
				<label class="layui-form-label">MiniAppId</label>
				<div class="layui-input-block">
					<input type="text"
						   id="mini_app_id333"
						   name="mini_app_id"
						   value="<%= mini_app_id %>"
						   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
				</div>
			</div>

				<div class="layui-form-item">
					<label class="layui-form-label">权限模式</label>
					<div class="layui-input-block">
						<select id="check_mode" name="check_mode" required="">
							<option value="">请选择权限模式</option>
							<option value="0" <% if (check_mode == 0) { %> selected <% } %> >按日期时间检测(0)</option>
							<option value="1" <% if (check_mode == 1) { %> selected <% } %> >按使用次数检测(1)</option>
							<option value="2" <% if (check_mode == 2) { %> selected <% } %> >总是有效(2)</option>

						</select>
					</div>
				</div>





				<!--<div class="layui-form-item layui-layout-admin">-->
			<!--<div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                    <button class="layui-btn" lay-submit="" lay-filter="edit-submit-for-pop">提交</button>
                    <a href="javascript:goBack()" class="layui-btn layui-btn-primary">返回</a>
                    <a href="<% $imports.goBack() %>"  class="layui-btn layui-btn-primary">返回2</a>
                </div>
            </div>-->
				<!--</div>-->
			<!--</form>-->
		</div>




</script>

<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-card-header">AppSuit</div>
		<div class="layui-card-body" style="padding: 15px;">
			<form class="layui-form" action="" lay-filter="component-form-group">
				{% if data.detail.Id %}
				<input name="id" type="hidden" value="{{ data.detail.Id }}"/>
				{% endif %}

				<!-- todo #FormFieldsHtml# -->
				<div class="layui-tab layui-tab-card">
					<ul class="layui-tab-title">
						<li class="layui-this">基础信息</li>
						<li>app列表</li>
					</ul>

					<div class="layui-tab-content">
						<div class="layui-tab-item layui-show">
							<!--
<div class="layui-form-item">
	<label class="layui-form-label">id</label>
	<div class="layui-input-block">
		<input type="text"
			   id="id"
			   name="id"
			   value="{{ data.detail.Id }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->
							<!--
<div class="layui-form-item">
	<label class="layui-form-label">deleted</label>
	<div class="layui-input-block">
		<input type="text"
			   id="if_del"
			   name="if_del"
			   value="{{ data.detail.IfDel }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->
							<!--
<div class="layui-form-item">
	<label class="layui-form-label">create</label>
	<div class="layui-input-block">
		<input type="text"
			   id="cdate"
			   name="cdate"
			   value="{{ data.detail.Cdate }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->
							<!--
<div class="layui-form-item">
	<label class="layui-form-label">update</label>
	<div class="layui-input-block">
		<input type="text"
			   id="udate"
			   name="udate"
			   value="{{ data.detail.Udate }}"
			   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
	</div>
</div>
     -->

							<div class="layui-form-item">
								<label class="layui-form-label">APP套餐码</label>
								<div class="layui-input-block">
									<input type="text"
										   id="suit_code"
										   name="suit_code"
										   value="{{ data.detail.SuitCode }}"
										   lay-verify="required" autocomplete="off" placeholder="APP套餐码是套餐的唯一标识，不能重复" class="layui-input" >
								</div>
							</div>


							<div class="layui-form-item">
								<label class="layui-form-label">APP套餐名</label>
								<div class="layui-input-block">
									<input type="text"
										   id="suit_name"
										   name="suit_name"
										   value="{{ data.detail.SuitName }}"
										   lay-verify="required" autocomplete="off" placeholder="" class="layui-input" >
								</div>
							</div>



							<div class="layui-form-item">
								<label class="layui-form-label">简述</label>
								<div class="layui-input-block">
									<textarea id="description" name="description" placeholder="" class="layui-textarea" >{{ data.detail.Description }}</textarea>
								</div>
							</div>


							<div class="layui-form-item">
								<label class="layui-form-label">排序</label>
								<div class="layui-input-block">
									<input type="text"
										   id="sort_idx"
										   name="sort_idx"
										   value="{{ data.detail.SortIdx }}"
										   lay-verify="title" autocomplete="off" placeholder="" class="layui-input" >
								</div>
							</div>

						</div>

						<div class="layui-tab-item">
							<!-- 表格 -->

							<script type="text/html" id="data-table-filter">
								<div class="layui-btn-container">
									<button class="layui-btn layui-btn-sm" lay-event="addApp">添加</button>
								</div>
							</script>


							<table class="layui-hide" id="data-table" lay-filter="data-table"></table>

							<!-- 操作工具栏 -->
							<script type="text/html" id="data-table-toolbar">
								<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
								<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
							</script>


						</div>
					</div>
				</div>






				<div class="layui-form-item layui-layout-admin">
					<div class="layui-input-block">
						<div class="layui-footer" style="left: 0;">
							<button class="layui-btn" lay-submit="" lay-filter="edit-submit">提交</button>
							<a href="javascript:goBack()" class="layui-btn layui-btn-primary">返回</a>


						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</div>


<script src="/public/layui/admin/layui/layui.js"></script>
<script src="/public/build/js/template-web.js"></script>
<script>
	layui.config({
		base: '/public/layui/admin/' //静态资源所在路径
	}).extend({
		index: 'lib/index' //主入口模块
	}).use(['index', 'form', 'laydate','jquery','upload','table'], function(){
		var $ = layui.$
				,admin = layui.admin
				,element = layui.element
				,layer = layui.layer
				,laydate = layui.laydate
				,form = layui.form;

		form.render(null, 'component-form-group');
		laydate.render({
			elem: '#LAY-component-form-group-date'
		});

		var tabledata = new Array();
		var table = layui.table;
		table.render({
			elem: '#data-table'
			//,url: '/admin/appmanager/AppSuit/listjson'  + '?appid={{data.Who.MiniAppId}}&tid={{data.Who.TenantId}}'
			,where : {"keyword":""}
			,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
			,toolbar: '#data-table-filter'
			,data: tabledata
			,cols: [[
				//#TableJsonFields#
				{field:'id',title: 'id', hide: true},
				{field:'if_del',title: 'deleted', hide: true},
				{field:'cdate',title: 'create', hide: true},
				{field:'udate',title: 'update', hide: true},
				{field:'app_suit_id',title: 'APP套餐ID', hide: false},
				{field:'suit_code',title: 'APP套餐码', hide: false, edit: 'number'},
				{field:'mini_app_id',title: 'MiniAppId', hide: false},
				{field:'check_mode',title: '权限校验模式', hide: false, edit: "number"},

				{fixed: 'right', title:'操作', toolbar: '#data-table-toolbar', width:120}
			]]
			,page: true
		});


		table.on('toolbar(data-table)', function (obj) {
			console.log("event")
			switch (obj.event) {
				case 'addApp': {
					addApp();
				}
					break;

			};
		});

		table.on('tool(data-table)', function (obj) {
			console.log("event", obj)

            if (obj.event === 'edit') {
				console.log("edit")
				var tableData = table.cache["data-table"];

				obj.data.mini_app_id = 1234567788;
				obj.data.check_mode = 1;
				//var html = template('app_item_edit_pop',obj.data);
				//html.helper("goBack", goBack);

				var render = template.compile($('#app_item_edit_pop').html());
				html = render(obj.data);


				//console.log("html", html)
				//document.getElementById('content').innerHTML = html;

				var url ="/admin/appmanager/AppSuit/editpage";
				var index = parent.layer.open({
					type: 1,
					anim: -1,
					area: ['700px','600px'],
					offset: '140px',
					//zIndex: 1000,
					content: html, //$('#app_item_edit_pop').html(),//$('#titleTpl'), //
					zIndex: layer.zIndex, //重点1
					//btn: ['保存', '关闭'],
					yes: function (layero) {
						//iframeSubmit(id, $callback);
						console.log("yes")

					},
					cancel : function() {
					    console.log("cancel");
					},
					success: function(layero){
						//layer.setTop(layero); //重点2
						console.log("table success:", tableData);
						//var iframe = window['layui-layer-ifram' + index]

						//tableData.findIndex(item=>item.id== obj.data.id)

						//$('#app_item_edit_pop').setAttribute("mini_app_id", "34335353");
						//console.log("$('#mini_app_id').value2:", $('#mini_app_id').value);
						//$('#mini_app_id').val("ddd111234345") ;
						//index.set
						//iframe.child(obj.data, index)
					},
					end: function () {
						console.log("edit end")
						//refresh()
						//window.location.reload();
					}
				});
			} else if (obj.event === 'del') {
				// parent.layer.confirm('真的删除行么', function (index) {
				//     obj.del();
				//     layer.close(index);
				// });

				layer.confirm('真的删除行么', function (index) {
					var oldData = table.cache["data-table"];
					//oldData.splice(oldData.findIndex(item=>item.id== obj.data.id),1);
					/*table.reload('data-table', {
						data: oldData
					});*/
					obj.del();
					layer.close(index);
				});
			}
		});

		function addApp() {
			var oldData = table.cache["data-table"];
			var newitem = {
				"mini_app_id": "111",
				"check_mode": "",
				"id": undefined
			};
			oldData.push(newitem);
			table.reload('data-table', {
				data: oldData
			});
		}

		/* 自定义验证规则 */
		form.verify({
			title: function(value){
				if(value.length < 0){
					return '请输入';
				}
			}
			,pass: [/(.+){6,12}$/, '密码必须6到12位']
			,content: function(value){
				layedit.sync(editIndex);
			}
		});

		// 文件上传
		var upload = layui.upload;
		upload.render({
			elem: '#upload-drag',
			url: '/admin/upload',
			done: function(res) {
				console.log(res)
				$("#img-upload").attr("src", res.data.imgurl);
				// TODO: $("#prdminipic").val(res.data.imgurl);
			}
		});


		/* 监听提交 */
		form.on('submit(edit-submit)', function(data){
			// parent.layer.alert(JSON.stringify(data.field), {
			//   title: '最终的提交信息'
			// })

			console.log("edit-submit");
			var applist = table.cache["data-table"];

			if (applist.length == 0) {
				parent.layer.alert("app信息不能为空", {
					title: '提示 2 '
				});
				return;
			}
			data.field.applist = applist
			$.ajax({
				type: "POST",
				url : "/admin/appmanager/AppSuit/editpage",
				data: data.field,
				async: true,
				dataType: 'JSON',
				contentType: 'application/json',
				error: function(request) {
					parent.layer.alert(JSON.stringify(request), {title: '操作失败'});
				},
				success: function(response) {
					console.log(response);
					//var rt = JSON.parse(response);
					var rt = response
					if(rt.code == 0){
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						parent.layer.close(index);
					}else{
						parent.layer.alert(rt.msg, {title: '操作失败'});
					}
				}
			});
			return false;
		});

		/* 监听指定开关
        form.on('switch(component-form-switchTest)', function(data){
          layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
            offset: '6px'
          });
          layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });*/
	});

	// 页面返回上一页面
	function goBack(){
		console.log("ddd")
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
		parent.layer.close(index);
	};

	window.goBack = goBack


	function refresh() {
		/*var searchKey = $("#keyword").val();
		table.reload('data-table', {
			where: {"keyword":searchKey}
		});*/
	}


</script>
</body>
</html>















